// composables/use-pagination.js
import { reactive, computed } from 'vue'

export function usePagination(defaultFilters = {}) {
    // 分页参数
    const pagination = reactive({
        page: 1,
        pageSize: 10
    })

    // 查询条件
    const filters = reactive({
        ...defaultFilters
    })

    // 合并后的查询参数
    const queryParams = computed(() => ({
        ...pagination,
        ...filters
    }))

    // 工具方法
    function setPage(page) {
        pagination.page = page
    }

    function setPageSize(size) {
        pagination.pageSize = size
    }

    function resetFilters() {
        Object.keys(filters).forEach(key => {
            filters[key] = defaultFilters[key]
        })
    }

    return {
        pagination,
        filters,
        queryParams,
        setPage,
        setPageSize,
        resetFilters
    }
}
